﻿using bordspil.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;


namespace bordspil.Controllers
{
    public class HomeController : Controller
    {


        public ActionResult Index()
        {
            var games = GameService.Instance.GetGameEntries();   // get all items from DB and do something with them, will give always the same instance (singleton patten)
            return View(games);                                  // connect got items with View.
        }

        public ActionResult About()
        {
            return View();
        }

        // this is main page for 'búa til leik'
        public ActionResult CreateGame(int? id)
        {
            var games = GameService.Instance.GetGameById(id.Value);
            return View(games);
        }

        // this will be used with 'búa til leik' and some Jquery... 
        [HttpPost]
        public ActionResult CreateGame(int? id, FormCollection coll)
        {
            // i stadinn fyrir database
            CreateGame table = new CreateGame();

            table.TableID = 1;
            table.Time = DateTime.Now;
            table.Player = coll["Name_of player"];
            table.Sit = coll["Sit"];

            Game game = GameService.Instance.GetGameById(id.Value);

            return Redirect("CreateGame");

        }

        // Connect 4 View
        public ActionResult Connect4()
        {
            return View();
        }

        // Olsen Olsen View
        public ActionResult OlsenOlsen()
        {
            return View();
        }
    }
}
